<?php

namespace app\test\controller;

use think\Controller;
use think\Db;
use think\exception\ErrorException;

class Login extends Controller
{
    public function login(){
        $request = request();
        $params = $request->param();
        $userName = $params['userName'];
        $passWord = $params['passWord'];
//        dump($params);
//        return json($userName);
//        return $userName;
        try {
            $pass = Db::name('administrator')->where('username',$userName)->value('password');
            if($pass == $passWord){
                $token = $this->makeToken();
                return "成功";
            }
            else{
                $token = '';
                return "失败";
            }
        }catch (ErrorException $ex){
            $token = '';
            return "失败";
        }
//        return $flag;
        return $token ;
    }
//  随机生成token
    private function makeToken()
    {

        $str = md5(uniqid(md5(microtime(true)), true)); //生成一个不会重复的字符串
        $str = sha1($str); //加密
        return $str;
    }
}
